//
//  ReportViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/5/11.
//

#import "ReportViewController.h"
#import "ReportCollectionViewCell.h"
@interface ReportViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic , copy) NSString * seletedString;
@property (nonatomic , strong) HeaderView * addButton;
@end

@implementation ReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"举报");
    // Do any additional setup after loading the view.
}

- (void)SQ_UIViewForSelfView{
    [self.collectionView registerClass:[ReportCollectionViewCell class] forCellWithReuseIdentifier:@"ReportCollectionViewCell"];
    [self.view addSubview:self.collectionView];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).offset(-FootHeight-90);
        make.top.equalTo(self.zx_navBar.mas_bottom);
    }];
    
    [self.view addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).offset(-FootHeight-30);
        make.height.mas_equalTo(48);
    }];
    [self SQ_Header];
}
- (void)SQ_Header{
    NSArray * array = @[@"垃圾广告",@"侮辱谩骂",@"政治敏感",@"刷水/骗赞",@"地域黑",@"未成年不适",@"低俗色情",@"违法违禁",@"涉嫌欺诈",@"网络暴力",@"引导私下交易",@"恐怖画面",@"不实信息",@"其他"];
    [self.jsonArray addObjectsFromArray:array];
    [self.collectionView reloadData];
}
-(void)SQ_ButtonClick{
    if (![self.seletedString isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"请选择举报原因!")];
        return;
    }
    [YJProgressHUD SQ_showMsgWithoutView:@""];
   NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:self.seletedString forKey:@"content"];
    [dic setObject:self.userid forKey:@"pid"];
    [dic setObject:self.type forKey:@"type"];
    [HttpTool post:Url45 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"举报成功")];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self SQ_popViewVC];
        });
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}


#pragma mark UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.jsonArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    ReportCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ReportCollectionViewCell" forIndexPath:indexPath];
    [cell SQ_name:[self.jsonArray objectAtIndex:indexPath.item] seleted:self.seletedString];
     return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
   
    return CGSizeMake((SCREEN_WIDETH-30)/2.f-1, 44);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10, 10, 0, 10);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    self.seletedString = [self.jsonArray objectAtIndex:indexPath.item];
    [self.collectionView reloadData];
}


- (HeaderView *)addButton{
    if (!_addButton) {
        _addButton = [[HeaderView alloc]init];
        _addButton.image = @"矩形";
        _addButton.colorString = @"#FFFFFF";
        [_addButton.btn addTarget:self action:@selector(SQ_ButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _addButton.layer.masksToBounds = YES;
        _addButton.text = SQNSLocalString(@"提交");
        _addButton.font = FONT_MEDIUM(18);
    }
    return _addButton;
}
@end
